! ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
! 
! Auxiliary Routines File
! 
! Generated by KPP-2.2.3 symbolic chemistry Kinetics PreProcessor
!       (http://www.cs.vt.edu/~asandu/Software/KPP)
! KPP is distributed under GPL, the general public licence
!       (http://www.gnu.org/copyleft/gpl.html)
! (C) 1995-1997, V. Damian & A. Sandu, CGRER, Univ. Iowa
! (C) 1997-2005, A. Sandu, Michigan Tech, Virginia Tech
!     With important contributions from:
!        M. Damian, Villanova University, USA
!        R. Sander, Max-Planck Institute for Chemistry, Mainz, Germany
! 
! File                 : aromatics_kpp_Util.f90
! Time                 : Thu Dec 17 19:38:34 2020
! Working directory    : /n/home08/kbates/Aromatics/MOZART
! Equation file        : aromatics_kpp.kpp
! Output root filename : aromatics_kpp
! 
! ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~



MODULE aromatics_kpp_Util

  USE aromatics_kpp_Parameters
  IMPLICIT NONE

CONTAINS



! User INLINED Utility Functions

! End INLINED Utility Functions

! Utility Functions from KPP_HOME/util/util
! ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
! 
! UTIL - Utility functions
!   Arguments :
! 
! ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

! ****************************************************************
!                            
! InitSaveData - Opens the data file for writing
!   Parameters :                                                  
!
! ****************************************************************

      SUBROUTINE InitSaveData ()

      USE aromatics_kpp_Parameters

      open(10, file='aromatics_kpp.dat')

      END SUBROUTINE InitSaveData

! End of InitSaveData function
! ****************************************************************

! ****************************************************************
!                            
! SaveData - Write LOOKAT species in the data file 
!   Parameters :                                                  
!
! ****************************************************************

      SUBROUTINE SaveData ()

      USE aromatics_kpp_Global
      USE aromatics_kpp_Monitor

      INTEGER i

      WRITE(10,999) (TIME-TSTART)/3600.D0,  &
                   (C(LOOKAT(i))/CFACTOR, i=1,NLOOKAT)
999   FORMAT(E24.16,100(1X,E24.16))

      END SUBROUTINE SaveData

! End of SaveData function
! ****************************************************************

! ****************************************************************
!                            
! CloseSaveData - Close the data file 
!   Parameters :                                                  
!
! ****************************************************************

      SUBROUTINE CloseSaveData ()

      USE aromatics_kpp_Parameters

      CLOSE(10)

      END SUBROUTINE CloseSaveData

! End of CloseSaveData function
! ****************************************************************

! ****************************************************************
!                            
! GenerateMatlab - Generates MATLAB file to load the data file 
!   Parameters : 
!                It will have a character string to prefix each 
!                species name with.                                                 
!
! ****************************************************************

      SUBROUTINE GenerateMatlab ( PREFIX )

      USE aromatics_kpp_Parameters
      USE aromatics_kpp_Global
      USE aromatics_kpp_Monitor

      
      CHARACTER(LEN=8) PREFIX 
      INTEGER i

      open(20, file='aromatics_kpp.m')
      write(20,*) 'load aromatics_kpp.dat;'
      write(20,990) PREFIX
990   FORMAT(A1,'c = aromatics_kpp;')
      write(20,*) 'clear aromatics_kpp;'
      write(20,991) PREFIX, PREFIX
991   FORMAT(A1,'t=',A1,'c(:,1);')
      write(20,992) PREFIX
992   FORMAT(A1,'c(:,1)=[];')

      do i=1,NLOOKAT
        write(20,993) PREFIX, SPC_NAMES(LOOKAT(i)), PREFIX, i
993     FORMAT(A1,A6,' = ',A1,'c(:,',I2,');')
      end do
      
      CLOSE(20)

      END SUBROUTINE GenerateMatlab

! End of GenerateMatlab function
! ****************************************************************


! End Utility Functions from KPP_HOME/util/util
! End of UTIL function
! ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~


! ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
! 
! Shuffle_user2kpp - function to copy concentrations from USER to KPP
!   Arguments :
!      V_USER    - Concentration of variable species in USER's order
!      V         - Concentrations of variable species (local)
! 
! ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

SUBROUTINE Shuffle_user2kpp ( V_USER, V )

! V_USER - Concentration of variable species in USER's order
  REAL(kind=dp) :: V_USER(NVAR)
! V - Concentrations of variable species (local)
  REAL(kind=dp) :: V(NVAR)

  V(145) = V_USER(1)
  V(128) = V_USER(2)
  V(134) = V_USER(3)
  V(172) = V_USER(4)
  V(51) = V_USER(5)
  V(155) = V_USER(6)
  V(89) = V_USER(7)
  V(152) = V_USER(8)
  V(39) = V_USER(9)
  V(1) = V_USER(10)
  V(54) = V_USER(11)
  V(33) = V_USER(12)
  V(162) = V_USER(13)
  V(131) = V_USER(14)
  V(119) = V_USER(15)
  V(186) = V_USER(16)
  V(2) = V_USER(17)
  V(3) = V_USER(18)
  V(34) = V_USER(19)
  V(102) = V_USER(20)
  V(92) = V_USER(21)
  V(123) = V_USER(22)
  V(85) = V_USER(23)
  V(109) = V_USER(24)
  V(161) = V_USER(25)
  V(70) = V_USER(26)
  V(120) = V_USER(27)
  V(150) = V_USER(28)
  V(142) = V_USER(29)
  V(86) = V_USER(30)
  V(168) = V_USER(31)
  V(95) = V_USER(32)
  V(166) = V_USER(33)
  V(156) = V_USER(34)
  V(98) = V_USER(35)
  V(43) = V_USER(36)
  V(135) = V_USER(37)
  V(68) = V_USER(38)
  V(188) = V_USER(39)
  V(88) = V_USER(40)
  V(96) = V_USER(41)
  V(97) = V_USER(42)
  V(52) = V_USER(43)
  V(53) = V_USER(44)
  V(42) = V_USER(45)
  V(138) = V_USER(46)
  V(4) = V_USER(47)
  V(60) = V_USER(48)
  V(170) = V_USER(49)
  V(115) = V_USER(50)
  V(124) = V_USER(51)
  V(163) = V_USER(52)
  V(5) = V_USER(53)
  V(149) = V_USER(54)
  V(140) = V_USER(55)
  V(137) = V_USER(56)
  V(106) = V_USER(57)
  V(132) = V_USER(58)
  V(130) = V_USER(59)
  V(148) = V_USER(60)
  V(154) = V_USER(61)
  V(144) = V_USER(62)
  V(160) = V_USER(63)
  V(17) = V_USER(66)
  V(18) = V_USER(67)
  V(6) = V_USER(70)
  V(169) = V_USER(73)
  V(143) = V_USER(74)
  V(126) = V_USER(75)
  V(129) = V_USER(76)
  V(147) = V_USER(77)
  V(110) = V_USER(78)
  V(151) = V_USER(79)
  V(56) = V_USER(80)
  V(7) = V_USER(81)
  V(8) = V_USER(82)
  V(182) = V_USER(83)
  V(180) = V_USER(84)
  V(127) = V_USER(85)
  V(165) = V_USER(86)
  V(121) = V_USER(87)
  V(100) = V_USER(88)
  V(122) = V_USER(89)
  V(181) = V_USER(90)
  V(61) = V_USER(91)
  V(58) = V_USER(92)
  V(164) = V_USER(93)
  V(99) = V_USER(94)
  V(174) = V_USER(95)
  V(136) = V_USER(96)
  V(116) = V_USER(97)
  V(35) = V_USER(98)
  V(159) = V_USER(99)
  V(179) = V_USER(100)
  V(185) = V_USER(101)
  V(183) = V_USER(102)
  V(117) = V_USER(103)
  V(31) = V_USER(104)
  V(175) = V_USER(105)
  V(187) = V_USER(106)
  V(78) = V_USER(107)
  V(36) = V_USER(108)
  V(9) = V_USER(109)
  V(157) = V_USER(110)
  V(81) = V_USER(111)
  V(37) = V_USER(112)
  V(158) = V_USER(113)
  V(133) = V_USER(114)
  V(82) = V_USER(115)
  V(146) = V_USER(116)
  V(10) = V_USER(117)
  V(173) = V_USER(118)
  V(184) = V_USER(119)
  V(171) = V_USER(120)
  V(87) = V_USER(121)
  V(62) = V_USER(122)
  V(63) = V_USER(123)
  V(176) = V_USER(124)
  V(178) = V_USER(125)
  V(167) = V_USER(126)
  V(103) = V_USER(127)
  V(93) = V_USER(128)
  V(104) = V_USER(129)
  V(125) = V_USER(130)
  V(79) = V_USER(131)
  V(44) = V_USER(132)
  V(153) = V_USER(133)
  V(94) = V_USER(134)
  V(46) = V_USER(135)
  V(49) = V_USER(136)
  V(11) = V_USER(137)
  V(71) = V_USER(138)
  V(12) = V_USER(139)
  V(139) = V_USER(140)
  V(80) = V_USER(141)
  V(13) = V_USER(142)
  V(14) = V_USER(143)
  V(15) = V_USER(144)
  V(16) = V_USER(145)
  V(32) = V_USER(146)
  V(50) = V_USER(147)
  V(141) = V_USER(148)
  V(177) = V_USER(149)
  V(64) = V_USER(150)
  V(59) = V_USER(151)
  V(118) = V_USER(152)
  V(19) = V_USER(153)
  V(20) = V_USER(154)
  V(21) = V_USER(155)
  V(22) = V_USER(156)
  V(23) = V_USER(157)
  V(24) = V_USER(158)
  V(25) = V_USER(159)
  V(26) = V_USER(160)
  V(27) = V_USER(161)
  V(28) = V_USER(162)
  V(29) = V_USER(163)
  V(30) = V_USER(164)
  V(91) = V_USER(165)
  V(40) = V_USER(166)
  V(107) = V_USER(167)
  V(47) = V_USER(168)
  V(48) = V_USER(169)
  V(41) = V_USER(170)
  V(45) = V_USER(171)
  V(112) = V_USER(172)
  V(73) = V_USER(173)
  V(72) = V_USER(174)
  V(65) = V_USER(175)
  V(74) = V_USER(176)
  V(66) = V_USER(177)
  V(90) = V_USER(178)
  V(75) = V_USER(179)
  V(55) = V_USER(180)
  V(67) = V_USER(181)
  V(101) = V_USER(182)
  V(57) = V_USER(183)
  V(113) = V_USER(184)
  V(108) = V_USER(185)
  V(114) = V_USER(186)
  V(76) = V_USER(187)
  V(83) = V_USER(188)
      
END SUBROUTINE Shuffle_user2kpp

! End of Shuffle_user2kpp function
! ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~


! ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
! 
! Shuffle_kpp2user - function to restore concentrations from KPP to USER
!   Arguments :
!      V         - Concentrations of variable species (local)
!      V_USER    - Concentration of variable species in USER's order
! 
! ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

SUBROUTINE Shuffle_kpp2user ( V, V_USER )

! V - Concentrations of variable species (local)
  REAL(kind=dp) :: V(NVAR)
! V_USER - Concentration of variable species in USER's order
  REAL(kind=dp) :: V_USER(NVAR)

  V_USER(1) = V(145)
  V_USER(2) = V(128)
  V_USER(3) = V(134)
  V_USER(4) = V(172)
  V_USER(5) = V(51)
  V_USER(6) = V(155)
  V_USER(7) = V(89)
  V_USER(8) = V(152)
  V_USER(9) = V(39)
  V_USER(10) = V(1)
  V_USER(11) = V(54)
  V_USER(12) = V(33)
  V_USER(13) = V(162)
  V_USER(14) = V(131)
  V_USER(15) = V(119)
  V_USER(16) = V(186)
  V_USER(17) = V(2)
  V_USER(18) = V(3)
  V_USER(19) = V(34)
  V_USER(20) = V(102)
  V_USER(21) = V(92)
  V_USER(22) = V(123)
  V_USER(23) = V(85)
  V_USER(24) = V(109)
  V_USER(25) = V(161)
  V_USER(26) = V(70)
  V_USER(27) = V(120)
  V_USER(28) = V(150)
  V_USER(29) = V(142)
  V_USER(30) = V(86)
  V_USER(31) = V(168)
  V_USER(32) = V(95)
  V_USER(33) = V(166)
  V_USER(34) = V(156)
  V_USER(35) = V(98)
  V_USER(36) = V(43)
  V_USER(37) = V(135)
  V_USER(38) = V(68)
  V_USER(39) = V(188)
  V_USER(40) = V(88)
  V_USER(41) = V(96)
  V_USER(42) = V(97)
  V_USER(43) = V(52)
  V_USER(44) = V(53)
  V_USER(45) = V(42)
  V_USER(46) = V(138)
  V_USER(47) = V(4)
  V_USER(48) = V(60)
  V_USER(49) = V(170)
  V_USER(50) = V(115)
  V_USER(51) = V(124)
  V_USER(52) = V(163)
  V_USER(53) = V(5)
  V_USER(54) = V(149)
  V_USER(55) = V(140)
  V_USER(56) = V(137)
  V_USER(57) = V(106)
  V_USER(58) = V(132)
  V_USER(59) = V(130)
  V_USER(60) = V(148)
  V_USER(61) = V(154)
  V_USER(62) = V(144)
  V_USER(63) = V(160)
  V_USER(66) = V(17)
  V_USER(67) = V(18)
  V_USER(70) = V(6)
  V_USER(73) = V(169)
  V_USER(74) = V(143)
  V_USER(75) = V(126)
  V_USER(76) = V(129)
  V_USER(77) = V(147)
  V_USER(78) = V(110)
  V_USER(79) = V(151)
  V_USER(80) = V(56)
  V_USER(81) = V(7)
  V_USER(82) = V(8)
  V_USER(83) = V(182)
  V_USER(84) = V(180)
  V_USER(85) = V(127)
  V_USER(86) = V(165)
  V_USER(87) = V(121)
  V_USER(88) = V(100)
  V_USER(89) = V(122)
  V_USER(90) = V(181)
  V_USER(91) = V(61)
  V_USER(92) = V(58)
  V_USER(93) = V(164)
  V_USER(94) = V(99)
  V_USER(95) = V(174)
  V_USER(96) = V(136)
  V_USER(97) = V(116)
  V_USER(98) = V(35)
  V_USER(99) = V(159)
  V_USER(100) = V(179)
  V_USER(101) = V(185)
  V_USER(102) = V(183)
  V_USER(103) = V(117)
  V_USER(104) = V(31)
  V_USER(105) = V(175)
  V_USER(106) = V(187)
  V_USER(107) = V(78)
  V_USER(108) = V(36)
  V_USER(109) = V(9)
  V_USER(110) = V(157)
  V_USER(111) = V(81)
  V_USER(112) = V(37)
  V_USER(113) = V(158)
  V_USER(114) = V(133)
  V_USER(115) = V(82)
  V_USER(116) = V(146)
  V_USER(117) = V(10)
  V_USER(118) = V(173)
  V_USER(119) = V(184)
  V_USER(120) = V(171)
  V_USER(121) = V(87)
  V_USER(122) = V(62)
  V_USER(123) = V(63)
  V_USER(124) = V(176)
  V_USER(125) = V(178)
  V_USER(126) = V(167)
  V_USER(127) = V(103)
  V_USER(128) = V(93)
  V_USER(129) = V(104)
  V_USER(130) = V(125)
  V_USER(131) = V(79)
  V_USER(132) = V(44)
  V_USER(133) = V(153)
  V_USER(134) = V(94)
  V_USER(135) = V(46)
  V_USER(136) = V(49)
  V_USER(137) = V(11)
  V_USER(138) = V(71)
  V_USER(139) = V(12)
  V_USER(140) = V(139)
  V_USER(141) = V(80)
  V_USER(142) = V(13)
  V_USER(143) = V(14)
  V_USER(144) = V(15)
  V_USER(145) = V(16)
  V_USER(146) = V(32)
  V_USER(147) = V(50)
  V_USER(148) = V(141)
  V_USER(149) = V(177)
  V_USER(150) = V(64)
  V_USER(151) = V(59)
  V_USER(152) = V(118)
  V_USER(153) = V(19)
  V_USER(154) = V(20)
  V_USER(155) = V(21)
  V_USER(156) = V(22)
  V_USER(157) = V(23)
  V_USER(158) = V(24)
  V_USER(159) = V(25)
  V_USER(160) = V(26)
  V_USER(161) = V(27)
  V_USER(162) = V(28)
  V_USER(163) = V(29)
  V_USER(164) = V(30)
  V_USER(165) = V(91)
  V_USER(166) = V(40)
  V_USER(167) = V(107)
  V_USER(168) = V(47)
  V_USER(169) = V(48)
  V_USER(170) = V(41)
  V_USER(171) = V(45)
  V_USER(172) = V(112)
  V_USER(173) = V(73)
  V_USER(174) = V(72)
  V_USER(175) = V(65)
  V_USER(176) = V(74)
  V_USER(177) = V(66)
  V_USER(178) = V(90)
  V_USER(179) = V(75)
  V_USER(180) = V(55)
  V_USER(181) = V(67)
  V_USER(182) = V(101)
  V_USER(183) = V(57)
  V_USER(184) = V(113)
  V_USER(185) = V(108)
  V_USER(186) = V(114)
  V_USER(187) = V(76)
  V_USER(188) = V(83)
      
END SUBROUTINE Shuffle_kpp2user

! End of Shuffle_kpp2user function
! ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~


! ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
! 
! GetMass - compute total mass of selected atoms
!   Arguments :
!      CL        - Concentration of all species (local)
!      Mass      - value of mass balance
! 
! ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

SUBROUTINE GetMass ( CL, Mass )

! CL - Concentration of all species (local)
  REAL(kind=dp) :: CL(NSPEC)
! Mass - value of mass balance
  REAL(kind=dp) :: Mass(1)

      
END SUBROUTINE GetMass

! End of GetMass function
! ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~



END MODULE aromatics_kpp_Util

